{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=1427
  Verdict: Accepted
}
uses SysUtils, Math;
 
var
   i,n,j,m,r:longint;
   a:array[0..1010,0..1010] of longint;
   mr,mc:array[0..1010] of longint;
 
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
read(n,m);
for i:=1 to n do mr[i]:=maxlongint;
for i:=1 to m do mc[i]:=-maxlongint;
for i:=1 to n do
    for j:=1 to m do begin
        read(a[i][j]);
        if a[i][j]<mr[i] then mr[i]:=a[i][j];
        if a[i][j]>mc[j] then mc[j]:=a[i][j];
    end;
r:=0;
for i:=1 to n do
    for j:=1 to m do
        if (a[i][j]=mr[i]) and (a[i][j]=mc[j]) then inc(r);
write(r);
end.